/* GUI CONVERTED from rwroru1a.p (converter v1.75) Sat Aug 12 23:18:08 2000 */
/* rwroru1a.p - ROUTING OPERATION COST CALCULATION                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/* REVISION: 7.3        LAST MODIFIED: 02/18/93     BY: emb *G701*      */
/* REVISION: 7.3        LAST MODIFIED: 05/12/93     BY: pma *GA86*      */
/* REVISION: 7.3        LAST MODIFIED: 11/20/95     BY: bcm *G1DD*      */
/* REVISION: 7.3        LAST MODIFIED: 01/02/96     BY: bcm *G1HV*      */
/* REVISION: 7.3        LAST MODIFIED: 05/20/96     BY: rvw *G1W4*      */


/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb          */
         {mfdeclre.i}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rwroru1a_p_1 "Update Operation Cost"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */


         define input parameter site as character.
         define input parameter csset as character.
         define input parameter routing as character.
         define input parameter bom_code as character.
         define input parameter ord_qty as decimal.
         define input parameter eff_date as date.
         define input parameter inc_yield like mfc_logical.

         define variable update-op like mfc_logical initial true
            label {&rwroru1a_p_1}.

         define variable part_yield as decimal no-undo initial 100.
         define variable cum_yield as decimal no-undo initial 100.

         define variable mtl_this_op as decimal no-undo.
         define variable lbr_this_op as decimal no-undo.
         define variable bdn_this_op as decimal no-undo.
         define variable sub_this_op as decimal no-undo.
         define variable ovh_this_op as decimal no-undo.
         define variable mtl_prev_op as decimal no-undo.
         define variable lbr_prev_op as decimal no-undo.
         define variable bdn_prev_op as decimal no-undo.
         define variable sub_prev_op as decimal no-undo.
         define variable ovh_prev_op as decimal no-undo.
         define variable mtl_in as decimal no-undo.
         define variable lbr_in as decimal no-undo.
         define variable bdn_in as decimal no-undo.
         define variable sub_in as decimal no-undo.
         define variable ovh_in as decimal no-undo.
/*G1W4*/ define variable phantom like pt_phantom no-undo.

         if update-op then do:
            for each iro_det exclusive-lock where
            iro_part = bom_code
            and iro_site = site
            and iro_cost_set = csset
            and iro_routing = routing:
               delete iro_det.
            end.
         end.

         for each ro_det no-lock where ro_routing = routing
         and (eff_date = ? or ro_start = ? or ro_start <= eff_date)
         and (eff_date = ? or ro_end = ? or eff_date <= ro_end)
         break by ro_routing by ro_op:
/*GUI*/ if global-beam-me-up then undo, leave.


            if update-op
            and first-of (ro_routing)
            and ro_op <> 0
            then do:
               for each ps_mstr no-lock where ps_par = bom_code
               and ps_op = 0
               and (eff_date = ? or ps_start = ? or ps_start <= eff_date)
               and (eff_date = ? or ps_end = ? or eff_date <= ps_end)
/*G1HV*/       and can-find (first pt_mstr where pt_part = ps_comp)
               and (ps_ps_code = "" or ps_ps_code = "X"):
/*GUI*/ if global-beam-me-up then undo, leave.


                  {gpsct01.i &part=ps_comp &set=csset &site=site}

/*G1W4*/          /* CHECK FOR GLOBAL PHANTOM; IF SO, ONLY ROLL-UP */
/*G1W4*/          /* LOWER LEVEL COSTS TO THE PARENT               */
/*G1W4*/          {gprun.i ""gpckphan.p"" "(input ps_comp,
                                            input site,
                                            output phantom)"}
/*GUI*/ if global-beam-me-up then undo, leave.

/*G1W4*/          if not phantom then
                  mtl_prev_op = mtl_prev_op +
                     sct_cst_tot * ps_qty_per * (100 / (100 - ps_scrp_pct)).
/*G1W4*/          else mtl_prev_op = mtl_prev_op +
/*G1W4*/             (sct_bdn_ll + sct_lbr_ll + sct_mtl_ll + sct_ovh_ll +
/*G1W4*/              sct_sub_ll) * ps_qty_per * (100 / (100 - ps_scrp_pct)).
               end.
/*GUI*/ if global-beam-me-up then undo, leave.

               mtl_in = mtl_prev_op.
            end.

            /* Note:                         */
            /* Yield handled differently for */
            /* subcontract.  You normally    */
            /* only pay for GOOD sub parts,  */
            /* while you expend lbr & bdn to */
            /* make both GOOD and BAD parts  */

            sub_this_op = (ro_sub_cost * part_yield * .01 * ro_yield_pct * .01).

            find wc_mstr no-lock where wc_wkctr = ro_wkctr
            and wc_mch = ro_mch no-error.

            if available wc_mstr then do:

               lbr_this_op = (((ro_setup / ord_qty) * wc_setup_rte)
                           + (ro_run * wc_lbr_rate)) * part_yield * .01.

/*G1DD** REPLACED SECTION WITH STANDARD EQUATION **
 *G1DD**       bdn_this_op = (((ro_setup / ord_qty)
 *G1DD**                   * (wc_setup_rte * wc_bdn_pc * .01
 *G1DD**                   + wc_bdn_rate + wc_mch_bdn * ro_mch_op))
 *G1DD**                   + (ro_run * (wc_lbr_rate * wc_bdn_pc * .01
 *G1DD**                   + wc_bdn_rate + wc_mch_bdn * ro_mch_op)))
 *G1DD**                   * part_yield * .01.                        **/

/*G1DD*/       /*! CALCULATE TOTAL OPERATION BURDEN USING THE STANDARD     *
                *  EQUATION.                                               */
/*G1DD*/       {gprun.i ""rwbdncal.p""
                           "( input 'TOTAL'              /* BURDEN COST TYPE */,
                              input no                  /* ACCUMULATE TOTAL? */,
                              input (wc_bdn_pc * 0.01)     /* BURDEN PERCENT */,
                              input wc_bdn_rate               /* BURDEN RATE */,
                              input wc_lbr_rate                /* LABOR RATE */,
                              input wc_mch_bdn        /* MACHINE BURDEN RATE */,
                              input ro_mch_op               /* MACHINES USED */,
                              input ord_qty                /* ORDER QUANTITY */,
                              input ro_run                  /* UNIT RUN TIME */,
                              input wc_setup_rte               /* SETUP RATE */,
                              input ro_setup                   /* SETUP TIME */,
                              input (part_yield * 0.01)     /* YIELD PERCENT */,
                              input-output bdn_this_op        /* BURDEN COST */
                            )"
               }
/*GUI*/ if global-beam-me-up then undo, leave.

            end.

            for each ps_mstr no-lock where ps_par = bom_code
            and ps_op = ro_op
            and (eff_date = ? or ps_start = ?
            or ps_start <= eff_date)
            and (eff_date = ? or ps_end = ? or eff_date <= ps_end)
/*G1HV*/    and can-find (first pt_mstr where pt_part = ps_comp)
            and (ps_ps_code = "" or ps_ps_code = "X"):
/*GUI*/ if global-beam-me-up then undo, leave.


               {gpsct01.i &part=ps_comp &set=csset &site=site}

/*G1W4*/       /* CHECK FOR GLOBAL PHANTOM; IF SO, ONLY ROLL-UP */
/*G1W4*/       /* LOWER LEVEL COSTS TO THE PARENT               */
/*G1W4*/       {gprun.i ""gpckphan.p"" "(input ps_comp,
                                         input site,
                                         output phantom)"}
/*GUI*/ if global-beam-me-up then undo, leave.

/*G1W4*/       if not phantom then
               mtl_this_op = mtl_this_op + sct_cst_tot
                  * ps_qty_per * (100 / (100 - ps_scrp_pct))
                  * part_yield * .01.
/*G1W4*/       else mtl_this_op = mtl_this_op +
/*G1W4*/          (sct_bdn_ll + sct_lbr_ll + sct_mtl_ll +
/*G1W4*/          sct_ovh_ll + sct_sub_ll) * ps_qty_per
/*G1W4*/          * (100 / (100 - ps_scrp_pct))
/*G1W4*/          * part_yield * .01.

            end.
/*GUI*/ if global-beam-me-up then undo, leave.


            mtl_in = mtl_in + mtl_this_op.
            lbr_in = lbr_in + lbr_this_op.
            bdn_in = bdn_in + bdn_this_op.
            sub_in = sub_in + sub_this_op.
/*GA86      ovh_in = bdn_in + ovh_this_op. */
/*GA86*/    ovh_in = ovh_in + ovh_this_op.

            cum_yield = cum_yield * .01 * ro_yield_pct.
            if inc_yield then part_yield = cum_yield.

            if update-op then do:
               find iro_det exclusive-lock where
               iro_part = bom_code
               and iro_site = site
               and iro_cost_set = csset
               and iro_routing = ro_routing
               and iro_op = ro_op
               no-error.

               if not available iro_det then do:
                  create iro_det.
                  assign iro_part = bom_code
                         iro_site = site
                     iro_cost_set = csset
                      iro_routing = ro_routing
                           iro_op = ro_op.
               end.

               assign iro_date = eff_date
                    iro_mtl_tl = mtl_in / (part_yield * .01)
                                 - mtl_prev_op
                    iro_lbr_tl = lbr_in / (part_yield * .01)
                                 - lbr_prev_op
                    iro_bdn_tl = bdn_in / (part_yield * .01)
                                 - bdn_prev_op
                    iro_sub_tl = sub_in / (part_yield * .01)
                                 - sub_prev_op
                    iro_mtl_ll = mtl_prev_op
                    iro_lbr_ll = lbr_prev_op
                    iro_bdn_ll = bdn_prev_op
                    iro_sub_ll = sub_prev_op.
                    iro_cost_tot = iro_mtl_tl + iro_mtl_ll
                                 + iro_lbr_tl + iro_lbr_ll
                                 + iro_bdn_tl + iro_bdn_ll
                                 + iro_sub_tl + iro_sub_ll
                                 + iro_ovh_tl + iro_ovh_ll.

               assign mtl_prev_op = iro_mtl_tl + iro_mtl_ll
                      lbr_prev_op = iro_lbr_tl + iro_lbr_ll
                      bdn_prev_op = iro_bdn_tl + iro_bdn_ll
                      sub_prev_op = iro_sub_tl + iro_sub_ll
                      ovh_prev_op = iro_ovh_tl + iro_ovh_ll
                      mtl_this_op = 0
                      lbr_this_op = 0
                      bdn_this_op = 0
                      sub_this_op = 0
                      ovh_this_op = 0.
            end.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*for each ro_det*/
